Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --auto-approve args to apply #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ptkimball
Copy link

Fix for terraform apply defaulting to interactive mode.

Started by user ptkimball
[EnvInject] - Loading node environment variables.
Building on master in workspace /var/lib/jenkins/workspace/Terraform PoC
[terraform-plugin] $ /var/lib/jenkins/tools/org.jenkinsci.plugins.terraform.TerraformInstallation/Terraform_0.11.3/terraform get
[terraform-plugin] $ /var/lib/jenkins/tools/org.jenkinsci.plugins.terraform.TerraformInstallation/Terraform_0.11.3/terraform apply -input=false "-state=/var/lib/jenkins/workspace/Terraform PoC/terraform-plugin/terraform-plugin.tfstate"

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
[32m+[0m create
[0m
Terraform will perform the following actions:

[32m [32m+[0m [32maws_instance.example
[0m id:
ami: "ami-12345678"
associate_public_ip_address:
availability_zone:
ebs_block_device.#:
ephemeral_block_device.#:
instance_state:
instance_type: "t2.nano"
ipv6_address_count:
ipv6_addresses.#:
key_name:
network_interface.#:
network_interface_id:
placement_group:
primary_network_interface_id:
private_dns:
private_ip:
public_dns:
public_ip:
root_block_device.#:
security_groups.#:
source_dest_check: "true"
subnet_id: "subnet-87654321"
tenancy:
volume_tags.%:
vpc_security_group_ids.#:
[0m
[0m
[0m[1mPlan:[0m 1 to add, 0 to change, 0 to destroy.[0m

[0m[1mDo you want to perform these actions?[0m
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.

[1mEnter a value:[0m [0m
[31m
[1m[31mError: [0m[0m[1mApply cancelled.[0m

[0m[0m[0m
FATAL: java.lang.Exception: Terraform Apply failed: 1
at org.jenkinsci.plugins.terraform.TerraformBuildWrapper.executeApply(TerraformBuildWrapper.java:249)
at org.jenkinsci.plugins.terraform.TerraformBuildWrapper.setUp(TerraformBuildWrapper.java:269)
at hudson.model.Build$BuildExecution.doRun(Build.java:157)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504)
at hudson.model.Run.execute(Run.java:1724)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:429)

Finished: FAILURE

Fix for `terraform apply` defaulting to interactive mode.

Started by user ptkimball
[EnvInject] - Loading node environment variables.
Building on master in workspace /var/lib/jenkins/workspace/Terraform PoC
[terraform-plugin] $ /var/lib/jenkins/tools/org.jenkinsci.plugins.terraform.TerraformInstallation/Terraform_0.11.3/terraform get
[terraform-plugin] $ /var/lib/jenkins/tools/org.jenkinsci.plugins.terraform.TerraformInstallation/Terraform_0.11.3/terraform apply -input=false "-state=/var/lib/jenkins/workspace/Terraform PoC/terraform-plugin/terraform-plugin.tfstate"

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  [32m+[0m create
[0m
Terraform will perform the following actions:

[32m  [32m+[0m [32maws_instance.example
[0m      id:                           <computed>
      ami:                          "ami-12345678"
      associate_public_ip_address:  <computed>
      availability_zone:            <computed>
      ebs_block_device.#:           <computed>
      ephemeral_block_device.#:     <computed>
      instance_state:               <computed>
      instance_type:                "t2.nano"
      ipv6_address_count:           <computed>
      ipv6_addresses.#:             <computed>
      key_name:                     <computed>
      network_interface.#:          <computed>
      network_interface_id:         <computed>
      placement_group:              <computed>
      primary_network_interface_id: <computed>
      private_dns:                  <computed>
      private_ip:                   <computed>
      public_dns:                   <computed>
      public_ip:                    <computed>
      root_block_device.#:          <computed>
      security_groups.#:            <computed>
      source_dest_check:            "true"
      subnet_id:                    "subnet-87654321"
      tenancy:                      <computed>
      volume_tags.%:                <computed>
      vpc_security_group_ids.#:     <computed>
[0m
[0m
[0m[1mPlan:[0m 1 to add, 0 to change, 0 to destroy.[0m

[0m[1mDo you want to perform these actions?[0m
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  [1mEnter a value:[0m [0m
[31m
[1m[31mError: [0m[0m[1mApply cancelled.[0m

[0m[0m[0m
FATAL: java.lang.Exception: Terraform Apply failed: 1
	at org.jenkinsci.plugins.terraform.TerraformBuildWrapper.executeApply(TerraformBuildWrapper.java:249)
	at org.jenkinsci.plugins.terraform.TerraformBuildWrapper.setUp(TerraformBuildWrapper.java:269)
	at hudson.model.Build$BuildExecution.doRun(Build.java:157)
	at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504)
	at hudson.model.Run.execute(Run.java:1724)
	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
	at hudson.model.ResourceController.execute(ResourceController.java:97)
	at hudson.model.Executor.run(Executor.java:429)

Finished: FAILURE
@the-sibyl
Copy link

I compiled and applied this on a Jenkins machine to do AWS EC2 spin-up. I had run into the same issue with the job aborting because "y" was not pressed.

Confirmed to work with Terraform v0.11.7, Jenkins ver. 2.89.3.

@dpires
Copy link
Member

dpires commented Mar 20, 2019

I haven't had a chance to verify if this is backwards compatible with older terraform versions? If not I think a checkbox/option should be available

@dpires
Copy link
Member

dpires commented Mar 20, 2019

It appears --auto-approve will break on anything older than 0.10.0 "flag provided but not defined: -auto-approve".

Also, with the addition of -auto-approve, -force was deprecated on terraform destroy and replaced with -auto-approve

hashicorp/terraform#17218

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants